package com.yuexunit.operationman.nbsy.module.OperationRiskAssessment.presenter.impl;

import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.OperationRiskAssessment.bean.RiskAssessmentBean;
import com.yuexunit.operationman.nbsy.module.OperationRiskAssessment.model.IRiskAssessmentDetailModel;
import com.yuexunit.operationman.nbsy.module.OperationRiskAssessment.presenter.IRiskAssessmentDetailPresenter;
import com.yuexunit.operationman.nbsy.module.OperationRiskAssessment.ui.view.IRiskAssessmentDetailView;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action0;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2017/7/24.
 */
public class RiskAssessmentDetailPresenter implements IRiskAssessmentDetailPresenter {
    private IRiskAssessmentDetailModel mModel;
    private IRiskAssessmentDetailView mView;

    public RiskAssessmentDetailPresenter(IRiskAssessmentDetailView view, IRiskAssessmentDetailModel model){
        mModel=model;
        mView=view;
    }


    @Override
    public void getRiskAssessmentDate(Map<String, String> praise) {
        mModel.getRiskAssessmentDate(praise)
                .subscribeOn(Schedulers.io())
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {
//                        log.info("UserPresenter_doInLogin_SHOW_DIALOG");
                        mView.loadingDialogStatus(AppConfig.SHOW_DIALOG);
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<RiskAssessmentBean>() {
                    @Override
                    public void onCompleted() {
                        mView.loadingDialogStatus(AppConfig.DISMISS_DIALOG);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.loadingDialogStatus(AppConfig.DISMISS_DIALOG);
                    }

                    @Override
                    public void onNext(RiskAssessmentBean riskAssessmentBean) {
                        mView.getRiskAssessmentDate(riskAssessmentBean);
                    }
                });
    }
}
